﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBullet : Bullet
{

	private void Start() {
		bullet = GetComponent<Collider2D>();
		shooter = transform.parent.GetComponent<Role>();
	}

	/// <summary>
	/// 子弹初始化, 只需获取攻击力即可
	/// </summary>
	/// <param name="shooter"></param>
	public override void SetIniAttributes(Role shooter) {
		base.SetIniAttributes(shooter);
		this.gameObject.SetActive(true);
	}

	/// <summary>
	/// 子弹击中目标
	/// </summary>
	/// <param name="other"></param>
	private void OnTriggerEnter2D(Collider2D other) {
		if (other.gameObject.GetComponent<Role>() != null) {
			// Enemy 击中 Player
			if (other.gameObject.GetComponent<Role>().RoleType == RoleType.Player) {
				if ((this.shooter as Enemy).Type == EnemyType.EnemyRocket)
					this.gameObject.SetActive(false);
				Debug.Log("受到子弹攻击");
				other.GetComponent<Player>().RecvAttack(Attack);
			}
		}

	}
}
